package org.leumasjaffe.initiativeTracker;
//import initiativeTracker.operator.CharacterImporter;

import java.io.IOException;

import org.leumasjaffe.initiativeTracker.distributed.controller.ServerProtocolFactory;


import edu.wpi.heineman.server.Server;
import edu.wpi.heineman.xml.Message;

/** Code to launch Server  from the command line. */
public class ServerLauncher {

	/** Execute the Server using the default port. */
	public static void main(String[] args) {
		// FIRST thing to do is register the protocol being used. There will be a single class protocol
		// that will be defined and which everyone will use. For now, demonstrate with skeleton protocol.
		if (!Message.configure("initiative.xsd"))
				System.exit(-1);
		
		// Start server and have ProtocolHandler be responsible for all XML messages.
		Server server = new Server(new ServerProtocolFactory());
	
		try {
			server.initiateSocket();
		} catch (IOException ioe) {
			System.err.println("Unable to launch server:" + ioe.getMessage());
			System.exit(-1);
		}
		
		if (args.length > 0) {
			Constants.uniAct = Boolean.parseBoolean(args[0]);
		}

		Constants.isDM = true;
		Constants.client = false;
		
//		CharacterImporter.importTracker("Initiative");
		
		// process all requests and exit.
		System.out.println("Server awaiting client connections");
		try {
			server.listenforClient();
			System.out.println("Server shutting down.");
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}    
	}
	
}
